package activities;

import java.util.Random;

import simpleDB.DatabaseHelper;
import simpleDB.PersonDataObject;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

import com.example.intellifit.R;

public class SimpleDBTest extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_simple_dbtest);

		DatabaseHelper dbHelper = new DatabaseHelper(getApplicationContext());
		dbHelper.dropTables();
		dbHelper.createTables();

		Random random = new java.util.Random();

		// ganz unten spezz-frezz auskommentiertes das hier stand
		String dayPrefix = "2013-11-";

		String dayPrefix3 = "2013-12-";
		for (int i = 10; i <= 30; i++) {
			String day = dayPrefix + i;

			String day3 = dayPrefix3 + i;
			for (int exId = 0; exId <= 5; exId++) {
				int reps = 24 + random.nextInt(4) * 8;
				int dur_mult = (random.nextInt(4) + 3) * 1000;

				int acc_mult = random.nextInt(35) + 62; // 62 bis 97 %

				dbHelper.addRepetitions(1, day, exId, reps, reps * acc_mult
						/ 100, reps * dur_mult);

				dbHelper.addRepetitions(1, day3, exId, reps, reps * acc_mult
						/ 100, reps * dur_mult);
			}
		}

		for (int i = 10; i <= 30; i++) {
			String day = dayPrefix + i;

			String day3 = dayPrefix3 + i;
			for (int exId = 11; exId <= 13; exId++) {
				int reps = 24 + random.nextInt(4) * 8;
				int dur_mult = (random.nextInt(4) + 3) * 1000;
				int acc_mult = random.nextInt(35) + 62; // 62 bis 97 %
				dbHelper.addRepetitions(1, day, exId, reps, reps * acc_mult
						/ 100, reps * dur_mult);

				dbHelper.addRepetitions(1, day3, exId, reps, reps * acc_mult
						/ 100, reps * dur_mult);
			}
		}

		dayPrefix = "2014-01-0";
		boolean c = false;
		for (int i = 1; i <= 21; i++) {
			if (i >= 10 && !c) {
				dayPrefix = (String) dayPrefix.subSequence(0,
						dayPrefix.length() - 1);
				c = true;
			}
			String day = dayPrefix + i;
			for (int exId = 0; exId <= 5; exId++) {

				int reps = 24 + random.nextInt(4) * 8;
				int dur_mult = (random.nextInt(4) + 3) * 1000;

				int acc_mult = random.nextInt(35) + 62; // 62 bis 97 %
				dbHelper.addRepetitions(1, day, exId, reps, reps * acc_mult
						/ 100, reps * dur_mult);
			}
		}
		dayPrefix = "2014-01-0";
		c = false;
		for (int i = 1; i <= 21; i++) {
			if (i >= 10 && !c) {
				dayPrefix = (String) dayPrefix.subSequence(0,
						dayPrefix.length() - 1);
				c = true;
			}
			String day = dayPrefix + i;
			for (int exId = 11; exId <= 13; exId++) {
				int reps = 24 + random.nextInt(4) * 8;
				int dur_mult = (random.nextInt(4) + 3) * 1000;
				int acc_mult = random.nextInt(35) + 62; // 62 bis 97 %
				dbHelper.addRepetitions(1, day, exId, reps, reps * acc_mult
						/ 100, reps * dur_mult);
			}
		}

		PersonDataObject pers = new PersonDataObject();
		pers.id = 1;
		pers.birthdate = "24-2-1980";
		pers.googletoken = "123";
		pers.height = 180;
		pers.name = "Franz Tester";
		pers.weight = 90;

		pers.level = 1;
		pers.transmitted = false;

		dbHelper.addPerson(pers);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.simple_dbtest, menu);
		return true;
	}

}

/*
 * generate some test data for the current month,the month before and the next
 * month
 */
// Calendar curr = Calendar.getInstance();
// Calendar prev = Calendar.getInstance();
// Calendar next = Calendar.getInstance();
// Calendar nnext = Calendar.getInstance();
// int max = 56;
// int min = 8;

// Collection<Integer> coll =
// Settings.getInstance().exerciseNameIDMapping.values();
//
// for (int i : coll) {
// curr = Calendar.getInstance();
// curr.set(Calendar.DAY_OF_MONTH, 1);
//
// prev = Calendar.getInstance();
// prev.add(Calendar.MONTH, -1);
// prev.set(Calendar.DAY_OF_MONTH, 1);
//
// next = Calendar.getInstance();
// next.add(Calendar.MONTH, 1);
// next.set(Calendar.DAY_OF_MONTH, 1);
//
// nnext = Calendar.getInstance();
// nnext.add(Calendar.MONTH, 2);
// nnext.set(Calendar.DAY_OF_MONTH, 1);
// for (int j = 0; j < curr.getActualMaximum(Calendar.DAY_OF_MONTH);
// j++) {
// dbHelper.addRepetitions(Settings.getInstance().getPersonID(),
// new SimpleDateFormat("yyyy-MM-dd").format(curr.getTime()), i, (int)
// (Math.random()
// * (max - min) + min),0);
// curr.add(Calendar.DATE, 1);
// }
// for (int j = 0; j < prev.getActualMaximum(Calendar.DAY_OF_MONTH);
// j++) {
// dbHelper.addRepetitions(Settings.getInstance().getPersonID(),
// new SimpleDateFormat("yyyy-MM-dd").format(prev.getTime()), i, (int)
// (Math.random()
// * (max - min) + min),0);
// prev.add(Calendar.DATE, 1);
// }
// for (int j = 0; j < next.getActualMaximum(Calendar.DAY_OF_MONTH);
// j++) {
// dbHelper.addRepetitions(Settings.getInstance().getPersonID(),
// new SimpleDateFormat("yyyy-MM-dd").format(next.getTime()), i, (int)
// (Math.random()
// * (max - min) + min),0);
// next.add(Calendar.DATE, 1);
// }
// for (int j = 0; j < nnext.getActualMaximum(Calendar.DAY_OF_MONTH);
// j++) {
// dbHelper.addRepetitions(Settings.getInstance().getPersonID(),
// new SimpleDateFormat("yyyy-MM-dd").format(nnext.getTime()), i, (int)
// (Math.random()
// * (max - min) + min),0);
// nnext.add(Calendar.DATE, 1);
// }
// }